import { Injectable, signal } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class SaveStateService {
  private _hasUnsavedChanges = signal(false);
  private _lastSaved = signal<Date | null>(null);
  private _currentProject = signal<string | null>(null);

  readonly hasUnsavedChanges = this._hasUnsavedChanges.asReadonly();
  readonly lastSaved = this._lastSaved.asReadonly();
  readonly currentProject = this._currentProject.asReadonly();

  markUnsaved() {
    this._hasUnsavedChanges.set(true);
  }

  markSaved() {
    this._hasUnsavedChanges.set(false);
    this._lastSaved.set(new Date());
  }

  setCurrentProject(projectName: string | null) {
    this._currentProject.set(projectName);
  }

  reset() {
    this._hasUnsavedChanges.set(false);
    this._lastSaved.set(null);
    this._currentProject.set(null);
  }
}
